import { createApp } from 'vue'
import router from './router'
import store from './stores'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import DataVVue3 from '@kjgl77/datav-vue3'
import VueTianditu from 'vue-tianditu'
import { useUserStore } from './stores/modules/user'
import pxtovwPlugin from './plugins/pxtovw-plugin' // 引入插件
import { tiandituConfig } from './config'
import App from './App.vue'
import './style/index.scss'

const app = createApp(App)

// 注册 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 使用插件（按顺序注册）
app.use(store)
app.use(router)
app.use(ElementPlus)
app.use(DataVVue3)
app.use(VueTianditu, {
  v: tiandituConfig.version,
  tk: tiandituConfig.apiKey
})
app.use(pxtovwPlugin) // ✅ 注册 px-to-vw 插件

// 在挂载应用之前检查认证状态
const userStore = useUserStore(store)
userStore.checkAuth()

app.mount('#app')